﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BrainTechLLC.Silverlight.Controls;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class EditLocationEdgeData : BaseDataVisualizer, ISingleItemDataVisualizer
    {        
        public override void SetVisualizedData(DataVisualizer vis, object o) { EdgeData = o as EdgeData; base.SetVisualizedData(vis, o); }
        public Type VisualizeType { get { return typeof(EdgeData); } }
        public string VisualizerName { get { return "EditLocationEdgeData"; } }

        public static readonly DependencyProperty EdgeDataProperty = DependencyProperty.Register(
            "EdgeData", typeof(EdgeData), typeof(EditLocationEdgeData), new PropertyMetadata(null, new PropertyChangedCallback(EdgeDataChanged)));

        public EdgeData EdgeData
        {
            get { return (EdgeData)GetValue(EdgeDataProperty); }
            set { SetValue(EdgeDataProperty, value); }
        }

        public static void HandleChange<T2>(DependencyObject d, DependencyPropertyChangedEventArgs e, Action<EditLocationEdgeData, T2> action)
        {
            d.HandleChange<EditLocationEdgeData, T2>(e, action, (t) => t.UpdateBindings());
        }

        private static void EdgeDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            HandleChange<EdgeData>(d, e, (t, val) => t.EdgeData = val);
        }

        public override void UpdateBindings()
        {
            if (EdgeData != null)
            {
                this.DataContext = EdgeData;
            }
        }

        public override string TitleText
        {
            get
            {
                return (EdgeData == null) ? string.Empty :
                    string.Format("EdgeData {0} ({1} Prop)", EdgeData.Keywords, EdgeData.PropertiesCount);
            }
        }

        public EditLocationEdgeData()
        {
            InitializeComponent();
        }

        public override void OnSaveData()
        {
            DataAccess.Client.StoreEdgeDataAsync(DataAccess.AssignedUniqueId, EdgeData);
        }

        private void ShowProps_Loaded(object sender, RoutedEventArgs e)
        {
            //editEdgeDataProperties.Window.Indent = Window.Indent + 1;         
        }

        private void EditAssociatedIDCollection_RequestEditID(object sender, ObjectEventArgsNonRef<long> e)
        {
            OnRequestEditID(sender, e);
        }
    }
}